package com.example.demo;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author 张成
 * @version 1.0
 * @date 2022/3/8 10:47
 */
public class ConfigDemo4Servlet extends HttpServlet {

    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
            throws ServletException, IOException {
        ServletContext servletContext = getServletContext();
        response.setContentType("text/html;charset=gb2312");
        PrintWriter out = response.getWriter();

        int sum = 1;
        for (int i = 1; i < 8; i++) {
            sum = sum * i;
        }
        servletContext.setAttribute("value",sum);
        out.println("<html><body>");
        out.println("计算成功 7！=" + sum + "<br>");

        out.println("</body></html>");
    }
}
